<template>
	<view>
		<XiaEditor
			:value="val"
			:readOnly="disabled || !writable"
			@editorChange="getEvent"
		>
		</XiaEditor>
		<view v-show="required && validator" class="requiredMessage">{{ requiredMessage }}</view>
	</view>
</template>

<script>
// import lRichTextEditor from '../lRichTextEditor/lRichTextEditor.vue'
import XiaEditor from '../xia-editor/xia-editor.vue'
export default {
	data() {
		return {
			val: '',
			validator: false
		}
	},
	components: { XiaEditor },
	props: {
		value: {
			type: String,
			default: ''
		},
		disabled: {
			type: Boolean,
			default: false
		},
		writable: {
			type: Boolean,
			default: true
		},
		required: {
			type: Boolean,
			default: false
		},
		requiredMessage: {
			type: String,
			default: ''
		}
	},
	computed: {
		validateStatus() {
			return this.$store?.state?.validate?.status || false
		}
	},
	watch: {
		value: {
			handler () {
				this.val = this.value || ''
			},
			immediate: true,
			deep: true
		},
		validateStatus() {
			if(this.validateStatus && this.required) {
				if(!this.val) {
					this.validator = true
				} else {
					this.validator = false
				}
			}
		},
		val: {
			handler () {
				if(this.validateStatus && this.required) {
					if(!this.val) {
						this.validator = true
					} else {
						this.validator = false
					}
				}
			},
			immediate: true,
		}
	},
	methods: {
		getEvent({delta, html, text}) {
			this.val = html
			this.$emit('input', this.val)
		}
	}
}
</script>

<style scoped>
.requiredMessage {
	width: 100%;
	height: 50rpx;
	line-height: 50rpx;
	color: #f56c6c;
	font-size: 22rpx;
}
</style>